What is the capacity of the ArrayList
in the picture?
10
What is its size?
3
List<E>
InterfaceLists of things are common in the real world and in programming. People make lists of things they need to buy and lists of things they need to do. A text editor keeps a list of pages. A test consists of a list of questions.
ArrayList
implements the List<E>
interface.
The List<E>
interface captures the idea of a list
without saying how the idea is implemented.
ArrayList
is just one implementation of the idea.
Recall that an interface consists of constants and method declarations.
A class that implements an interface must implement each
of the methods listed in the interface.
There are no constants in List<E>
,
but there are many methods.
A list is an ordered collection of elements.
Duplicate elements are allowed in an ArrayList
(and in most other implementations of List<E>
).
Elements in a list can be accessed by their index, as with an array.
There are methods to add elements, get elements, remove
elements, and search for elements (and many other methods).
What is the index of the first cell of a list?